/**
 * @author takaratsunehito
 */

/**
 * カウントダウン用のタイマー
 * 
 * @param {Integer} remainTime 残り時間(ミリ秒表現)
 */
function CountdownTimer(count_time) {
	this.is_stoped = true;
	this.count_time = count_time;
	this.offset = 0; // 一度タイマーを停止した際のカウントの値
};

CountdownTimer.prototype = {
    getString: function(){
        var now = new Date().getTime();
        var count = Math.ceil(Math.max((this.count_time - (now - this.start_time + this.offset)) / 1000, 0));
        if(count == 0){
			this.stop();
		}
		
		var hour = Math.floor(count / (60 * 60));
        var minute = Math.floor(count / 60 % 60);
        var second = count % 60;
        
		return "%02.0d:%02.0d:%02.0d".sprintf(hour, minute, second);
    },
    
    start: function(){
        this.start_time = new Date().getTime();
		this.is_stoped = false;
    },
    
    stop: function(){
    	this.is_stoped = true;
		
		// 現在のカウントの値を保存
		var now = new Date().getTime();
		this.offset = now - this.start_time + this.offset;
    },
    
    isStoped: function(){
    	return this.is_stoped;
    }
};
